// Author: Connor Wells // Date: 02/05/2013 // Theme: 2D Array Stuff #include #include #include using namespace std; void INPUTAR(int ARR[][], int ROWSL, int COLMl); void ADDROWS(int AR[][], int ROW1, int RW2); void SUBROWS(int array[][], int RW1, int RW2); void ADDCOLM(int ar[][], int COL1, int COL2); void SUBCOLM(int RAY[][], int CL1, int CL2); void COPYARR(int RR[][], int RZ, int CZ); void RMAXNUM(int RY[100][100], int RS, int COS); void CMAXNUM(int XC[100][100], int X, int Y); void RMINNUM(int BK[100][100], int RB, int CB); void CMINNUM(int QU[100][100], int ROWB, int COLB); void REPLACE(int VW[100][100], int D, int H); void PRINTAR(int GH[100][100], int A, int B); int rows; int colm; int ROWSL; int COLML; const int ROWSB = 100; const int COLMB = 100; double ARRAYL[ROWSL][COLML]; double ARRAYB[ROWSB][COLMB]; ofstream outputFile; int main() { outputFile.open("2D Array Things"); INPUTAR(ARRAYL, ROWSL, COLML); ADDROWS(ARRAYL, ROWSL, ROWSL); SUBROWS(ARRAYL, ROWSL, ROWSL); ADDCOLM(ARRAYL, COLML, COLML); SUBCOLM(ARRAYL, COLML, COLML); COPYARR(ARRAYL, ROWSL, COLML); RMAXNUM(ARRAYB, ROWSB, COLMB); CMAXNUM(ARRAYB, ROWSB, COLMB); RMINNUM(ARRAYB, ROWSB, COLMB); CMINNUM(ARRAYB, ROWSB, COLMB); REPLACE(ARRAYB, ROWSB, COLMB); PRINTAR(ARRAYB, ROWSB, COLMB); outputFile.close(); return 0; } void INPUTAR(double ARR[][], int ROWSL, int COLML) { cout << "How many rows will the first array have?"; cin >> ROWSL; cout << "How many columns will the first array have?"; cin >> COLML; cout << "\nEnter the dazta for:\n"; for (rows = 0; rows < ROWSL; rows++) { for (colm = 0; colm < COLML; colm++) { cout << "Row " << (rows + 1); cout << ", Column " << (colm + 1); cin >> ARR[rows][colm]; } } cout << "\nThe first array is: " << ARR[ROWSL][COLML] << "\n"; } void ADDROWS(double AR[][], int row1, int row2) { int sum1; int sum2; for(colm = 0; colm < COLML; colm++) { sum1 = sum1 + AR[row1][colm]; } for(colm = 0; colm < COLML; colm++) { sum2 = sum2 + AR[row2][colm]; } cout << "\nthe sum of 2 rows is: " << sum1 + sum2 << ".\n"; } void SUBROWS(double array[][], int rows1, int rows2) { int dif1; int dif2; for(colm = 0; colm < COLML; colm++) { dif1 = dif1 - array[rows1][colm]; } for(colm = 0; colm < COLML; colm++) { dif2 = dif2 - array[rows2][colm]; } cout << "\nThe difference b/tw 2 rows is: " << dif2 - dif1 << ".\n"; } void ADDCOLM(double ar[][], int colm1, int colm2) { int SUM1; int SUM2; for(rows = 0; rows < ROWSL; rows++) { SUM1 = SUM1 + ar[rows][colm1]; } for(rows = 0; rows < ROWSL; colm++) { SUM2 = SUM2 + ar[rows][colm2]; } cout << "\nThe sum of 2 columns is: " << SUM1 + SUM2 << ".\n"; } void SUBCOLM(double RAY[][], int colm1, int colm2) { int DIF1; int DIF2; for(rows = 0; rows < ROWSL; rows++) { DIF1 = DIF1 - RAY[rows][colm1]; } for(rows = 0; rows < ROWSL; rows++) { DIF2 = DIF2 - RAY[rows][colm2]; } cout << "\nThe difference b/tw 2 columns is: " << DIF2 - DIF1 << ".\n"; } void COPYARR(double RR[100][100], int RZ, int CZ) { for (rows = 0; rows < RZ; rows++) { for (colm = 0; colm < CZ; colm++) { RR[RZ][CZ] = ARRAYB[ROWSB][COLMB]; } } cout << "\nThe copied array is:\n" << ARRAYB[ROWSB][COLMB] << ".\n"; } void RMAXNUM(double RY[100][100], int RS, int COS) { int highest; for (int rw = 0; rw < RS; rw++) { highest = RY[rw][0]; for (int clm = 0; clm < COS; clm++) { if ( RY[rw][clm] > highest) { highest = RY[rw][clm]; } } } cout << "The highest number in Row " << ROWSB << "is " << highest << ".\n"; } void CMAXNUM(double XC[100][100], int X, int Y) { int HIGH; for (int CM = 1; CM < Y; CM++) { HIGH = XC[0][CM]; for (int RW = 0; RW < X; RW++) { if ( XC[RW][CM] > HIGH) { HIGH = XC[RW][CM]; } } } cout << "The highest number in Column " << COLMB << "is " << HIGH << ".\n"; } void RMINNUM(double BK[100][100], int RB, int CB) { int lowest; for (int rx = 1; rx < RB; rx++) { lowest = BK[rx][0]; for (int cx = 0; cx < CB; cx++) { if ( BK[rx][cx] < lowest) { lowest = BK[rx][cx]; } } } cout << "The lowest number in Row " << ROWSB << "is " << lowest << ".\n"; } void CMINNUM(double QU[100][100], int ROWB, int COLB) { int LOW; for (int CN = 0; CN < COLB; CN++) { LOW = QU[0][CN]; for (int rH = 0; rH < ROWB; rH++) { if ( QU[rH][0] < LOW) { LOW = QU[rH][CN]; } } cout << "The lowest number in Column " << COLMB << "is " << LOW << ".\n"; } } void REPLACE(double VW[100][100], int D, int H) { for (int f = 0; f < D; f++) { for (int c = 0; c < H; c++) { VW[1][1] = 100; } } } void PRINTAR(double GH[100][100], int A, int B) { for (int a = 0; a < A; a++) { for (int b = 0; b < B; b++) { cout << GH[A][B] << " z"; } } cout << "\n"; }